// pages/aboutus/aboutus.js
const wh = require("../../utils/wh.js");
const WxParse = require('../../wxParse/wxParse.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    company_info: [],
    phone: '',
    latitude: 0,
    longitude: 0,
    address: ''
  },
  call:function() {
    let that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.phone,
    })
  },
  about:function(){
    let that = this,
      postUrl = '/api/madetoorder.decorate.index/about_us';
    wh.Post(postUrl, {}, function (res) {
      if (res.compnay_desc != '' && res.compnay_desc != undefined && res.compnay_desc != null) {
        WxParse.wxParse('company_desc', 'html', res.compnay_desc, that);
      }
      that.setData({
        company_info: res,
        phone: res.service_tel,
        latitude: res.lat,
        longitude: res.lng,
        address: res.map_name
      });
    });
  },
  //地图导航
  go: function () {
    var that = this;
    wx.getLocation({
      type: 'gcj02', //返回可以用于wx.openLocation的经纬度  
      success: function (res) {
        var latitude = res.latitude
        var longitude = res.longitude
        var latitudeIdx = parseFloat(that.data.latitude);
        var longitudeIdx = parseFloat(that.data.longitude);
        var name = that.data.address;
        wx.openLocation({
          latitude: latitudeIdx,
          longitude: longitudeIdx,
          name: name,
          scale: 28
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.about()
  }
})